﻿using System;

namespace 里氏转换
{
	class Program
	{
		static void Main(string[] args)
		{
			//子类可以赋值给父类
			Person p = new Student();
			//如果父类中装的是子类可以强制转换成子类
			Student ss = (Student)p;
			/* is:转换判断成功ture 否则false
			 * as:转换成功就成功 不成功就赋值null
			 */
			if (p is Techer)
			{
				Techer ts= (Techer)p;
				Console.WriteLine("转换成功");
			}
			else
			{
				Console.WriteLine("转换失败");
			}

			Student t = p as Student;
			t.StudentSayHello();
			Console.ReadKey();
			
		}
	}
	class Person
	{
		public void PersonSayhello()
		{
			Console.WriteLine("Person Hello World!");
		}
	}
	class Student : Person
	{
		public void StudentSayHello()
		{
			Console.WriteLine("Student Hello World!");
		}
	}
	class Techer : Person
	{
		public void TecherSayHello()
		{
			Console.WriteLine("Techer Hello World!");
		}
	}
}
